package com.lzh.crm.controller;

import com.lzh.crm.pojo.Order;
import com.lzh.crm.pojo.OrderDTO;
import com.lzh.crm.pojo.Result;
import com.lzh.crm.service.OrderService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Resource
    private OrderService orderService;

    //创建工单
    @PostMapping("/insert")
    public Result insert(@RequestBody Order order){
        orderService.insert(order);
        return Result.success("创建成功");
    }

    //删除工单
    @DeleteMapping("/delete")
    public Result delete(Integer orderId){
        orderService.delete(orderId);
        return Result.success("删除成功");
    }

    //修改工单
    @PutMapping("/update")
    public Result update(@RequestBody Order order){
        orderService.update(order);
        return Result.success("修改成功");
    }

    //查询工单
    @GetMapping("/selectAll")
    public Result<List<OrderDTO>> selectAll(){
        List<OrderDTO> orderList = orderService.selectAll();
        return Result.success(orderList);
    }

    //条件查询工单
    @GetMapping("/selectNeed")
    public Result<List<OrderDTO>> selectNeed(OrderDTO orderDTO){
        List<OrderDTO> orderList = orderService.selectNeed(orderDTO);
        return Result.success(orderList);
    }
}
